﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entity;
using BLL;
using BLL.Access;
using System.Data;
using Platform.Http;
using Web.Class;
using Platform.Common;
using DevExpress.Web;
using DevExpress.Web;
using System.IO;

namespace Web.Controls.LAIHAN
{

    public partial class UCYUETIAOZHZXX : System.Web.UI.UserControl
    {
        #region 属性
        private string _YONGHUBH;
        public string YONGHUBH
        {
            get { return _YONGHUBH; }
            set { _YONGHUBH = value; }
        }
        #endregion

        #region 变量
        /// <summary>
        /// 访问数据库
        /// </summary>
        SpHelper _sphelper = new SpHelper();

        /// <summary>
        /// 来函用户信息
        /// </summary>
        YS_LH_YONGHUXXProcess laihanyhxx = new YS_LH_YONGHUXXProcess();

        /// <summary>
        /// 来函信息
        /// </summary>
        YS_LH_LAIHANXXProcess blllh = new YS_LH_LAIHANXXProcess();

        /// <summary>
        /// 流程
        /// </summary>
        YS_LH_LAIHANLCJLBLL lcbll = new YS_LH_LAIHANLCJLBLL();

        /// <summary>
        /// 月调整
        /// </summary>
        YS_LH_YUETIAOZProcess bllyue = new YS_LH_YUETIAOZProcess();
        /// <summary>
        /// 用户信息BLL
        /// </summary>
        YS_YG_YONGHUXXBLL yhbll = new YS_YG_YONGHUXXBLL();

        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        #endregion

        #region 方法
        public void BindControl(string requestid,out string laihanbh)
        {
            if (requestid.Trim().Length == 0)
            {
                laihanbh = "";
                ClearValue();
                return;
            }
            int id = Convert.ToInt32(requestid);
            YS_LH_LAIHANXX lh = blllh.SelectYS_LH_LAIHANXX(id);
            if (lh == null)
            {
                laihanbh = "";
                return;
            }
            this.YONGHUBH = lh.S_YONGHUBH;
            laihanbh = lh.S_LAIHANBH;
            txtSLBH.Text = lh.S_XUKEBH;
            txtXKBH.Text = lh.S_TONGYIBM;
            DataTable lcxx = lcbll.SelectYS_LH_LAIHANLCJLsDynamic(string.Format(" S_LAIHANBH='{0}' and I_LIUCHENGBH={1} ", lh.S_LAIHANBH, 2), "", null);
            if (lcxx != null && lcxx.Rows.Count > 0)
            {
                txtSLRQ.Text = Convert.ToDateTime(lcxx.Rows[0]["D_StartDate"]).ToString("yyyy-MM-dd");
                DataTable user = BusinessTool.GetTextAndValue("view_as_userinfo", "UserID", "UserName", null, string.Format("UserID={0} ", lcxx.Rows[0]["I_CAOZUOR"])).Tables[0];

                txtYWY.Text = user.Rows[0]["Value"].ToString();
            }
            int? Errcode = 0;
            DataSet jhxx = new SpHelper().P_YS_LH_YUEDUTZJHXXCX(BusinessTool.ZHANDIANBH(), (int)lh.I_TZY, (int)lh.I_TZM, lh.S_YONGHUBH.Trim(), out Errcode);
            if (Errcode < 0)
            {
                throw new Exception("系统数据缺失,请联系技术人员");
            }
            if (jhxx != null && jhxx.Tables.Count > 0 && jhxx.Tables[0] != null && jhxx.Tables[0].Rows.Count > 0)
            {
                DataRow dr = jhxx.Tables[0].Rows[0];
                txtSYCYE.Text = dr["V_ShangYueCYE"].ToString();
                txtSYJJE.Text = dr["V_ShangYuJJE"].ToString();
                txtSYL.Text = dr["V_ShiYongL"].ToString();
                txtSYSY.Text = dr["V_ShangYueSY"].ToString();

                txtCYBL.Text = dr["V_ChaoYongBL"].ToString();
                txtCYE.Text = dr["V_ChaoYongE"].ToString();
                txtCYL.Text = dr["V_ChaoYongL"].ToString();
                txtGBL.Text = dr["V_GuBiaoL"].ToString();

                txtHGL.Text = dr["V_HuiGuanL"].ToString();
                txtJJJE.Text = dr["V_JiaJiaJE"].ToString();
                txtJJL.Text = dr["V_JiaJiaL"].ToString();
                txtJJLV.Text = dr["V_JiaJiaLv"].ToString() + "%";
                txtJJIANL.Text = dr["V_JiJianL"].ToString();


                txtYJH.Text = dr["V_YuanJiH"].ToString();

                txtZCYJE.Text = "0";
                txtZJJJE.Text = "0";
                txtZJJL.Text = "0";
            }
            /*
            int y = Convert.ToInt32(lh.I_Y);
            int m = Convert.ToInt32(lh.I_M);
           
            DataSet dssy = _sphelper.P_YS_LH_YONGHUYSSJCX(y, m, lh.S_YONGHUBH.Trim(), null);
            if (dssy != null && dssy.Tables.Count > 0 && dssy.Tables[0] != null && dssy.Tables[0].Rows.Count > 0)
            {
                DataRow dr = dssy.Tables[0].Rows[0];

                txtSYCYE.Text = dr["N_CHAOJIHJE"].ToString();
                txtSYJJE.Text = dr["N_JIAJIAJE"].ToString();
                txtSYL.Text = dr["I_SHIYONGSL"].ToString();
                txtSYSY.Text = dr["I_SHIYONGSL"].ToString();

            }
            if (m == 1)
            {
                y = y - 1;
                m = 12;
            }
            else
            {
                m = m - 1;
            }
            DataSet ds = _sphelper.P_YS_LH_YONGHUYSSJCX(y, m, lh.S_YONGHUBH.Trim(), null);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];

                txtCYBL.Text = dr["I_JIAJIACS"].ToString();
                txtCYE.Text = dr["N_CHAOJIHJE"].ToString();
                txtCYL.Text = dr["I_CHAOJIHSL"].ToString();
                txtGBL.Text = dr["I_GUBIAOS"].ToString();

                txtHGL.Text = dr["I_HUIGUANL"].ToString();
                txtJJJE.Text = dr["N_JIAJIAJE"].ToString();
                txtJJL.Text = dr["I_JIAJIAL"].ToString();
                txtJJLV.Text = dr["I_JIAJIAL"].ToString();
                txtJJIANL.Text = dr["I_JIJIANJH"].ToString();


                txtYJH.Text = dr["I_YUANJIHUA"].ToString();

                txtZCYJE.Text = "0";
                txtZJJJE.Text = "0";
                txtZJJL.Text = "0";
            }
            */
            DataTable userdt = yhbll.SelectYS_YG_YONGHUXXesDynamic(string.Format(" S_YONGHUH='{0}' and I_LEIXING=0 and i_jlzt=0", lh.S_YONGHUBH), "", null);
            
            //DataTable userdt = laihanyhxx.SelectYS_LH_YONGHUXXesDynamic(string.Format(" S_YONGHUBH='{0}' and S_LAIHANBH='{1}'", lh.S_YONGHUBH, lh.S_LAIHANBH), "", null);
            if (userdt != null && userdt.Rows.Count > 0)
            {
                txtYHM.Text = userdt.Rows[0]["S_YONGHUM"].ToString();
                cFUFEI.Checked = (userdt.Rows[0]["I_CHENNUOFF"].ToString() == "1");
                cTUOSHOU.Checked = (userdt.Rows[0]["I_SHOUFEIFS"].ToString() == "1");
            }
           
            SetControlStatus();
        }
        private void ClearValue()
        {
            //txtLHBH.Text = "";
            txtSLBH.Text = "";
            txtXKBH.Text = "";

            txtCYBL.Text = "";
            txtCYE.Text = "";
            txtCYL.Text = "";
            txtGBL.Text = "";

            txtHGL.Text = "";
            txtJJJE.Text = "";
            txtJJL.Text = "";
            txtJJLV.Text = "";
            txtJJIANL.Text = "";


            txtYJH.Text = "";

            txtZCYJE.Text = "";
            txtZJJJE.Text = "";
            txtZJJL.Text = "";

            txtSYCYE.Text = "";
            txtSYJJE.Text = "";
            txtSYL.Text = "";
            txtSYSY.Text = "";

            txtSLRQ.Text = "";
            txtYWY.Text = "";
            txtYHM.Text = "";
            //txtYHSQL.Text = "";
        }
        private void SetControlStatus()
        {
            cTUOSHOU.Enabled = false;
            cFUFEI.Enabled = false;

            txtSLBH.Enabled = false;
            txtXKBH.Enabled = false;

            txtCYBL.Enabled = false;
            txtCYE.Enabled = false;
            txtCYL.Enabled = false;
            txtGBL.Enabled = false;

            txtHGL.Enabled = false;
            txtJJJE.Enabled = false;
            txtJJL.Enabled = false;
            txtJJLV.Enabled = false;
            txtJJIANL.Enabled = false;


            txtYJH.Enabled = false;

            txtZCYJE.Enabled = false;
            txtZJJJE.Enabled = false;
            txtZJJL.Enabled = false;

            txtSYCYE.Enabled = false;
            txtSYJJE.Enabled = false;
            txtSYL.Enabled = false;
            txtSYSY.Enabled = false;

            txtSLRQ.Enabled = false;
            txtYWY.Enabled = false;
            txtYHM.Enabled = false;
            //txtYHSQL.Enabled = false;
        }

        #endregion
    }
}